package com.yunquan.ohana.ui.calendar.event.add

import androidx.core.graphics.toColorInt
import androidx.databinding.ObservableField
import com.yunquan.ohana.base.binding.command.BindingAction
import com.yunquan.ohana.base.binding.command.BindingCommand
import com.yunquan.ohana.base.ui.BaseViewModel
import com.yunquan.ohana.base.ui.ItemViewModel
import com.yunquan.ohana.entity.RoleEntity

class AddEventRoleItemViewModel<T : BaseViewModel>(viewModel: T) : ItemViewModel<T>(viewModel) {

    var data: RoleEntity? = null
    val prefix = ObservableField<String>()
    val inner = ObservableField<Int>()
    val outer = ObservableField<Int>()
    val normal = ObservableField<Int>()

    val checked = ObservableField(false)

    constructor(viewModel: T, data: RoleEntity, checked: Boolean = false) : this(viewModel) {
        this.data = data
        this.checked.set(checked)
        this.prefix.set(data.name?.first()?.toString())
        this.inner.set(data.getColorData().inner.toColorInt())
        this.outer.set(data.getColorData().outer.toColorInt())
        this.normal.set(data.getColorData().normal.toColorInt())
    }

    fun setChecked(checked: Boolean) {
        this.checked.set(checked)
    }

    val onItemClick = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            val b = checked.get()!!
            checked.set(!b)
        }
    })
}